import * as vscode from 'vscode';
import {dedent} from "../../../utils";

// documentation中使用了代码块，代码块中写的事makedown格式，首行不能为空
let nodeItems = [
    {
        "label": "Node_Create",
        "insertText": dedent`
        GUI:Node_Create(\${1:parent}, \${2:ID}, \${3:x}, \${4:y})
        `,
        "documentation": dedent`# 创建节点
        [在线文档](http://engine-doc.996m2.com/web/#/22/2169)

        | 参数   | 必选 | 类型   | 注释        |
        | :----- | :--- | :----- | :---------- |
        | parent | 是   | obj    | 父节点对象  |
        | ID     | 是   | string | 唯一ID      |
        | x      | 是   | int    | 位置 横坐标 |
        | y      | 是   | int    | 位置 纵坐标 |

        - 示例代码

        \`\`\`
        local node = GUI:Node_Create(parent, "node", 0, 0)
        \`\`\`
        `
    }
]



export function getCompletionItems(): vscode.CompletionItem[] {


    const completionItems: vscode.CompletionItem[] = [];
    nodeItems.forEach((item: any) => {
        completionItems.push(createFunctionCompletionItem(item.label, item.insertText, item.documentation));
    });
    return completionItems;
}

function createFunctionCompletionItem(label: string, insertText: string, documentation?: string): vscode.CompletionItem {
    const item = new vscode.CompletionItem(label, vscode.CompletionItemKind.Function);
    item.insertText = new vscode.SnippetString(insertText);
    if (documentation) {
        item.documentation = new vscode.MarkdownString(documentation);
    }
    return item;
}
